# @Time  : 2021/7/26 14:56
# @Author: zhanfengzhen
# @Email : zhanfengzhen@126.com
# @File  : conftest.py
# !/usr/bin/env python
# -*- coding: UTF-8 -*-
import os

import pytest
import yaml
from selenium import webdriver

#复用浏览器
@pytest.fixture()
def remote_web():
    option = webdriver.ChromeOptions()
    option.debugger_address = '127.0.0.1:9222'
    dri = webdriver.Chrome(options=option)
    dri.get('https://work.weixin.qq.com/wework_admin/frame')
    return dri

#获取cookies
@pytest.fixture()
def get_cookie(remote_web):
    cookies = remote_web.get_cookies()
    return cookies

#获取文件路径
def get_filePath():
    file = os.path.dirname(__file__)
    cookies = os.path.join(file, 'cookies.yaml')
    return cookies

#把cookie写入文件
@pytest.fixture()
def write_yml(get_cookie):
    with open(get_filePath(), 'w+', encoding='utf-8') as f:
        yaml.safe_dump(get_cookie, f)

#读取yaml文件里的cookie
@pytest.fixture()
def get_yamlCookie():
    with open(get_filePath(), encoding='utf-8') as f:
        cookie = yaml.safe_load(f)
        return cookie
